<template>
  <div>
    <FilterTable
      ref="table"
      :isSelectColumn="false"
      :columns="columns"
      height="auto"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>

    <Drawer :visible.sync="visible" :title="title" :width="1200" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <salesVisitDetail :type="type" :recordVersion="recordVersion" :careTargetId="careTargetId" :employeeId="employeeId" :billId="billId" @changeHandle="changeHandle" @close="closeHandler" />
    </Drawer>

    <Drawer :visible.sync="visible3" :title="title" :width="1200" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <specialHolidayDetail @changeHandle="changeHandle" @close="closeHandler" />
    </Drawer>

    <Drawer :visible.sync="visible4" :title="title" :width="1200" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <customerBirthdayDetail @changeHandle="changeHandle" @close="closeHandler" />
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { formatdate } from '@/utils/index';
import { queryCareTask } from '@/api/customerRepair/visitRules/salesVisit2';
import salesVisitDetail from '../visitRules/salesVisit2/salesVisitDetail';
import specialHolidayDetail from '../customerCare/customerHoliday2/specialHolidayDetail';
import customerBirthdayDetail from '../customerCare/potentialCustomerBirthday2/customerBirthdayDetail';

export default {
  name: 'careTask',
  components: {
    salesVisitDetail,
    specialHolidayDetail,
    customerBirthdayDetail
  },
  mixins: [dictionary],
  props: {
    employeeId: String,
    careTargetId: String
  },
  data() {
    return {
      columns: this.createTableColumns(),
      fetchApi: queryCareTask,
      fetchParams: { employeeId: this.employeeId, careTargetId: this.careTargetId },
      handleType: '',
      title: '',
      formData: {},
      recordVersion: '',
      type: '',
      billId: '',
      visible: false,
      visible2: false,
      visible3: false,
      visible4: false
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          fixed: 'left',
          width: 50,
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.careHandle(props.row)}>
                  关爱
                </el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '关爱类型',
          dataIndex: 'careTypeCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <div>{this.createDictText(props.row.careTypeCode, '1572')}</div>;
          }
        },
        {
          title: '任务编号',
          dataIndex: 'taskNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '分配日期',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            if (props.row.createdAt && props.row.createdAt != '') {
              return <div>{formatdate(new Date(parseInt(props.row.createdAt)), 1)}</div>;
            }
          }
        },
        {
          title: '要求完成日期',
          dataIndex: 'requiredDate',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            if (props.row.requiredDate && props.row.requiredDate != '') {
              return <div>{formatdate(new Date(parseInt(props.row.requiredDate)), 1)}</div>;
            }
          }
        },
        {
          title: '关爱名称',
          dataIndex: 'careName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '关爱人员',
          dataIndex: 'employeeName',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    careHandle(row) {
      this.type = 'add';
      this.billId = row.billId + '';
      this.employeeId = row.careEmpId + '';
      this.careTargetId = row.careTargetId + '';
      this.recordVersion = row.recordVersion + '';
      if (row.careTypeCode == 15721001 || row.careTypeCode == 15721002) {
        this.title = row.careTypeCode == 15721001 ? '售前回访关爱' : '销售回访关爱';
        this.visible = true;
      } else if (row.careTypeCode == 15721003) {
        this.visible4 = true;
      } else if (row.careTypeCode == 15721005) {
        this.visible3 = true;
      }
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less"></style>
